#include <cstdlib>
#include <cmath>

enum Sides {PS_NONE, PS_WHITE, PS_BLACK};
enum Types {PT_NONE, PT_KING, PT_QUEEN, PT_BISHOP, PT_KNIGHT, PT_CASTLE, PT_PAWN};

class Coord
{
public:
    int x, y;
    Coord() : x(0), y(0) {}
    Coord(int X, int Y) : x(X), y(Y) {}
    bool operator== (const Coord &r);
    bool operator!= (const Coord &r);
};

typedef Coord Piece;

class Board
{
public:

    // This is a 9x9 array to store the board piece data.
    // The 9th row and 9th column is the impossible position and is refered
    // to when there is an error. Don't forget that arrays start from 0.
    Piece pieceset[9][9];

    int enpassant[3];

    bool castling[3][3];
    int side;

    int side_switch ();
    int side_switch (int target);
    bool blocked (Coord ref_from, Coord ref_diff);
    Piece & tiles (Coord target);
    Coord find (Piece target, Coord start = Coord(0, 0));
    int capt (Coord targetpos);
    int chk (Coord ref_from, Coord ref_to, bool simulate, int promotion);

    Board()
    {
        // Clear the board
        for (int x = 0; x < 8; x++)
            for (int y = 0; y < 8; y++)
                pieceset[x][y] = Piece(PS_NONE, PT_NONE);
        // Reset the En Passant
        for (int x = 0; x < 3; x++)
            enpassant[x] = -1;
        // Reset the castling
        for (int x = 0; x < 3; x++)
            for (int y = 0; y < 3; y++)
                castling[x][y] = true;
        // White starts first
        side = PS_WHITE;
    }
};
int board_possible(Board target, int side);
